﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Management.Automation;
using System.Text;
using Sitecore.Data;

namespace Cognifide.PowerShell.Shell.Commands
{
    /// <summary>
    /// Cmdlet. allows to execute query on Sitecore databases (the database can be named to restrict query to
    /// single database).
    /// 
    /// <author>Szymon Kuzniak (szymon.kuzniak@cognifide.com)</author>
    /// </summary>
    [Cmdlet("Get", "XpathItems")]
    public class GetXpathItemsCommand : DatabaseContextBaseCommand
    {
        /// <summary>
        /// Sitecore xpath query.
        /// </summary>
        [Parameter(Position = 0)]
        public string XPath { get; set; }

        protected override void ProcessRecord(IEnumerable<Database> databases)
        {
            foreach (Database database in databases)
            {
                WriteObject(database.SelectItems(XPath));
            }

        }
    }
}
